package kz.edu.sdu.itech.pcs.common;

import java.util.SortedSet;
import java.util.TreeSet;

public class Alphabet {
   TreeSet<Character> set = new TreeSet<Character>();

   public Alphabet() {

   }

   public void clear() {
      set.clear();
   }

   public int size() {
      return set.size();
   }

   public void add(String seq) {
      if (seq.length() == 3 && seq.charAt(1) == '-') {
         int s = seq.charAt(0);
         int e = seq.charAt(2);
         if (s < e) {
            while (s <= e) {
               set.add((char) s++);
            }
         }
      } else {
         for (int i = 0; i < seq.length(); i++) {
            set.add(seq.charAt(i));
         }
      }
   }

   public SortedSet<Character> getSet() {
      return set;
   }

   public Character[] getArray() {
      return set.toArray(new Character[set.size()]);
   }

   @Override
   public String toString() {
      StringBuffer sb = new StringBuffer();
      for (Character c : set) {
         sb.append(c);
      }
      return sb.toString();
   }
}
